package com.api.devices.controller;

import com.api.common.core.controller.BaseController;
import com.api.common.core.page.TableDataInfo;
import com.api.common.utils.AESUtils;
import com.api.devices.domain.query.IpcQuery;
import com.api.devices.domain.vo.IpcVo;
import com.api.devices.domain.vo.SourceVo;
import com.api.devices.service.ISourceService;
import com.api.devices.service.IiPcService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/realTime")
public class RealTimeController extends BaseController {
    @Autowired
    ISourceService realTimeService;

    @Autowired
    IiPcService iPcService;

    @PostMapping("/info")
    public TableDataInfo info(@RequestBody SourceVo vo){
        try{
            IpcVo ipcVo = new IpcVo();
            ipcVo.setIpcCode(vo.getIpcCode());
            IpcQuery query = iPcService.search(ipcVo);

            if(ObjectUtils.isNotEmpty(query)){
                vo.setPassword(AESUtils.loginDecrypt(query.getPwd()));
                vo.setIp(query.getIp());
                return getDataTable(realTimeService.realTime(vo));
//            return getDataTable(resourceService.resourceList(vo));
            } else {
                return getDataPageError("没有对应IPC");
            }
        } catch (Exception e) {
            return getDataPageError(e.getMessage());
        }
    }
}
